#include "drv_speak_led.h"
//pb5 tx（发送open-close） pc11 rx（接收open-close）  			pc10 tx
void drv_speak_led_init(void)
{
	GPIO_InitTypeDef  GPIO_InitStruct;
	USART_InitTypeDef  USART_InitStruct;
	NVIC_InitTypeDef  NVIC_InitStruct;
	
	RCC_AHB1PeriphClockCmd( RCC_AHB1Periph_GPIOC,  ENABLE);
	RCC_APB1PeriphClockCmd( RCC_APB1Periph_UART4,  ENABLE);

	GPIO_InitStruct.GPIO_Mode=GPIO_Mode_AF;
	GPIO_InitStruct.GPIO_OType=GPIO_OType_PP;
	GPIO_InitStruct.GPIO_Pin=GPIO_Pin_11|GPIO_Pin_10;
	GPIO_InitStruct.GPIO_PuPd=GPIO_PuPd_UP;
	GPIO_InitStruct.GPIO_Speed=GPIO_Speed_50MHz;
	GPIO_Init(  GPIOC,& GPIO_InitStruct);

	GPIO_PinAFConfig(  GPIOC,  GPIO_PinSource11,  GPIO_AF_UART4);
	GPIO_PinAFConfig(  GPIOC,  GPIO_PinSource10,  GPIO_AF_UART4);

	USART_InitStruct.USART_BaudRate=115200;
	USART_InitStruct.USART_HardwareFlowControl=USART_HardwareFlowControl_None;
	USART_InitStruct.USART_Mode=USART_Mode_Rx|USART_Mode_Tx;
	USART_InitStruct.USART_Parity=USART_Parity_No;
	USART_InitStruct.USART_StopBits=USART_StopBits_1;
	USART_InitStruct.USART_WordLength=USART_WordLength_8b;
	USART_Init(  UART4, & USART_InitStruct);

	USART_ITConfig( UART4,  USART_IT_RXNE,  ENABLE);
	USART_ITConfig(UART4,  USART_IT_IDLE,  ENABLE);

	NVIC_InitStruct.NVIC_IRQChannel=UART4_IRQn;
	NVIC_InitStruct.NVIC_IRQChannelCmd=ENABLE;
	NVIC_InitStruct.NVIC_IRQChannelPreemptionPriority=0;
	NVIC_InitStruct.NVIC_IRQChannelSubPriority=1;
	NVIC_Init(& NVIC_InitStruct);

	USART_Cmd( UART4,  ENABLE);
	USART_ClearFlag(  UART4,  USART_FLAG_TC);
}
void drv_speak_led(void)
{
		if(strcmp((const char*)recv,"open")==0||strcmp((const char*)recv,"opene")==0)
	{
		GPIO_ResetBits(GPIOF, GPIO_Pin_8);
		i=0;
		return;
	}
	else if(strcmp((const char*)recv,"close")==0)
	{
		GPIO_SetBits( GPIOF,  GPIO_Pin_8);
		i=0;
		return;
	}
}